package com.shiwaixiangcun.customer.ui.dialog;

import android.app.Activity;
import android.app.DialogFragment;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.shiwaixiangcun.customer.R;
import com.shiwaixiangcun.customer.module.property.PaymentRecordActivity;
import com.shiwaixiangcun.customer.ui.activity.ResidentCertificationActivity;
import com.shiwaixiangcun.customer.utils.DisplayUtil;

/**
 * Author   Administrator
 * Date     2018/4/10
 * Desc     eg
 *
 * @author Administrator
 */
public class PopupWidowDialog extends DialogFragment implements View.OnClickListener {

    public static boolean isShow = false;
    private Activity mActivity;
    private TextView mTvRecord;
    private TextView mTvAdd;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        isShow = true;
        mActivity = this.getActivity();
        setStyle(android.support.v4.app.DialogFragment.STYLE_NO_TITLE, R.style.UpdateAppDialog);
    }

    @Override
    public void onDetach() {
        super.onDetach();
        mActivity = null;
    }


    @Override
    public void onStart() {
        super.onStart();
        //点击window外的区域 是否消失
        int margin = DisplayUtil.INSTANCE.dip2px(mActivity, 8);
        int marginTop = DisplayUtil.INSTANCE.dip2px(mActivity, 56);
        getDialog().setCanceledOnTouchOutside(true);
        Window window = getDialog().getWindow();
        assert window != null;
        window.setGravity(Gravity.TOP);
        window.getDecorView().setPadding(margin, marginTop, 0, margin);

        WindowManager.LayoutParams lp = window.getAttributes();
        lp.width = WindowManager.LayoutParams.WRAP_CONTENT;
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        window.setAttributes(lp);

    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
        Bundle bundle = getArguments();
        if (null != bundle) {


        }
        return inflater.inflate(R.layout.popup_list, container, false);

    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initView(view);
    }

    private void initView(View view) {
        mTvRecord = view.findViewById(R.id.tv_record);
        mTvAdd = view.findViewById(R.id.tv_add_property);

        mTvAdd.setOnClickListener(this);

        mTvRecord.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        Intent intent = new Intent();
        switch (v.getId()) {
            case R.id.tv_add_property:

                Bundle bundle = new Bundle();
                bundle.putString("type", "add");
                intent.putExtras(bundle);
                intent.setClass(mActivity, ResidentCertificationActivity.class);
                startActivity(intent);
                dismiss();
                break;
            case R.id.tv_record:
                intent.setClass(mActivity, PaymentRecordActivity.class);
                startActivity(intent);
                dismiss();
                break;
            default:
                break;
        }
    }
}
